package com.xiyou.week01.array;

import java.util.Arrays;

/**
 * 283. 移动零
 *
 * @ClassName：Solution
 * @Author：西柚
 * @Date：2021/11/12 10:13 下午
 * @Versiion：1.0
 */
public class MoveZeroes {

    /**
     * 输入: [0,1,0,3,12]
     * 输出: [1,3,12,0,0]
     *
     * @param nums
     */
    public static void moveZeroes(int[] nums) {
        int n = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != 0) {
                nums[n] = nums[i];
                n++;
            }
        }

        while (n < nums.length) {
            nums[n] = 0;
            n++;
        }

        System.out.println(Arrays.toString(nums));
    }

    public static void main(String[] args) {
        int[] nums = {0, 1, 0, 3, 12};

        moveZeroes(nums);
    }

}
